<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php



class FXP
{
    
    private static $_logger;
    private static $_db_manager;
    
    public static function getVersion()
    {
        return '0.1.0-dev';
    }

    
    public static function import($alias,$forceInclude=false) {
        
    }
    
    
    
    public static function autoLoader($className)
    {
                                if (isset(self::$_classMaps[$className]))
        {
            include(FXP_PATH.self::$_classMaps[$className]);
        }

        else
        {
                                                if (strpos($className, '\\') === false)
            {
                include($className.'.php');
            }
            else
            {
                                                                return false;
            }
            return class_exists($className, false) || interface_exists($className, false);
        }

        return true;
    }

    
    public static function trace(
        $msg, 
        $category = 'application'
        )
    {
        if (FXP_DEBUG)
            self::log($msg, MLogger::LEVEL_TRACE, $category);
    }

    
    public static function log(
        $msg, 
        $level      = MLogger::LEVEL_INFO, 
        $category   = 'application'
        )
    {
        if (self::$_logger === null)
        {
            self::$_logger = MLogger::getInstance();
        }
        
        if (self::$_db_manager === null)
        {
            self::$_db_manager = MDbManager::getInstance();
        }
        
        if ($level == MLogger::LEVEL_INFO) {
            self::$_logger->info($msg);
        } elseif ($level == MLogger::LEVEL_TRACE) {
            self::$_logger->trace($msg);
        } elseif ($level == MLogger::LEVEL_WARNING) {
            self::$_logger->warn($msg);
        } elseif ($level == MLogger::LEVEL_ERROR) {
            self::$_logger->error($msg);
        } elseif ($level == MLogger::LEVEL_PROFILE) {
            self::$_logger->info($msg);
        }
    }
    
    
    public static function beginProfile($token,$category='application')
    {
        self::log('begin:'.$token, MLogger::LEVEL_PROFILE);
    }

    
    public static function endProfile($token,$category='application')
    {
                $spend_time = microtime(true)-FXP_BEGIN_TIME;
        self::log('end:'.$token.'花费时间：'.$spend_time, MLogger::LEVEL_PROFILE);
    }

    
    public static function t(
        $message,
        $params     = array(),
        $language   = null
        )
    {
                                if ($params === array())
            return $message;

        if (!is_array($params))
            $params = array($params);

                                return strtr($message, $params);
    }

    
    private static $_classMaps = array(
                                'MComponent'            => '/common/MComponent.php',
        'MModel'                => '/common/MModel.php',
        'MCache'                => '/common/MCache.php',
        'MDbManager'            => '/common/MDbManager.php',
        'MApplicationComponent' => '/common/MApplicationComponent.php',
        'MUrlManager'           => '/common/MUrlManager.php',
        'MException'            => '/common/MException.php',
        'MUtils'                => '/common/MUtils.php',
    	'MSecret'               => '/common/MSecret.php',
        'MFieldVerifier'        => '/common/MFieldVerifier.php',
        'MConst'                => '/common/MConst.php',
        'MUserManager'          => '/common/cache/MUserManager.php',
        'MOptionOperate'        => '/common/MOptionOperate.php',

                                'MLogger'               => '/common/MLogger.php',
        'Logger'                => '/log4php/Logger.php',
        'LoggerHierarchy'       => '/log4php/LoggerHierarchy.php',
        'LoggerLayout'          => '/log4php/LoggerLayout.php',
        'LoggerLevel'           => '/log4php/LoggerLevel.php',
        'LoggerRoot'            => '/log4php/LoggerRoot.php',
        'LoggerAppender'        => '/log4php/LoggerAppender.php',
        'LoggerAppenderPool'    => '/log4php/LoggerAppenderPool.php',
        'LoggerReflectionUtils' => '/log4php/LoggerReflectionUtils.php',
        'LoggerConfigurator'    => '/log4php/LoggerConfigurator.php',
        'LoggerLoggingEvent'    => '/log4php/LoggerLoggingEvent.php',
        'LoggerConfiguratorIni' => '/log4php/configurators/LoggerConfiguratorIni.php',
        'LoggerAppenderFile'    => '/log4php/appenders/LoggerAppenderFile.php',
        'LoggerOptionConverter' => '/log4php/helpers/LoggerOptionConverter.php',
        'LoggerLayoutSimple'    => '/log4php/layouts/LoggerLayoutSimple.php',
        'LoggerRendererDefault' => '/log4php/renderers/LoggerRendererDefault.php',
        'LoggerRendererObject'  => '/log4php/renderers/LoggerRendererObject.php',
        'LoggerRendererMap'     => '/log4php/renderers/LoggerRendererMap.php',

                                'MAuthrization'             => '/controller/MAuthrization.php',
        'MDataController'           => '/controller/MDataController.php',
        'MAPIController'            => '/controller/MAPIController.php',
        'MMetaException'            => '/controller/MMetaException.php',
        'MAuthorizationException'   => '/controller/MAuthorizationException.php',
        'MUploadFileController'     => '/controller/MUploadFileController.php',
        'MPartUploadController'     => '/controller/MPartUploadController.php',
        'MPartDownloadController'   => '/controller/MPartDownloadController.php',
        'MCreateFolderController'   => '/controller/fileops/MCreateFolderController.php',
        'MFilePostController'       => '/controller/files/MFilePostController.php',
        'MFileGetController'        => '/controller/files/MFileGetController.php',
        'MFilePutController'        => '/controller/files/MFilePutController.php',
        'MCreateFolderController'   => '/controller/fileops/MCreateFolderController.php',
        'MAccountInfoController'    => '/controller/account/MAccountInfoController.php',
        'MDeleteController'         => '/controller/fileops/MDeleteController.php',
        'MMoveController'           => '/controller/fileops/MMoveController.php',
        'MCopyController'           => '/controller/fileops/MCopyController.php',
        'MFileopsException'         => '/controller/fileops/MFileopsException.php',
        'MFilesException'           => '/controller/files/MFilesException.php',
        'MFilesCommon'              => '/controller/files/MFilesCommon.php',
        'MFilesecController'        => '/controller/files/MFilesecController.php',
        'MUnmountController'        => '/controller/device/MUnmountController.php',
        'MMetadataController'       => '/controller/MMetadataController.php',
        'MSharesController'         => '/controller/file_shares/MSharesController.php',
        'MDownSharesController'     => '/controller/file_shares/MDownSharesController.php',
        'MThumbnailsController'     => '/controller/thumbnails/MThumbnailsController.php',
        'MThumbnailBase'            => '/controller/thumbnails/MThumbnailBase.php',
        'MRevisionsController'      => '/controller/revisions/MRevisionsController.php',
        'MVersionCheckController'   => '/controller/version/MVersionCheckController.php',
        'MSharesBase'               => '/controller/file_shares/MSharesBase.php',
        'MMediasController'         => '/controller/medias/MMediasController.php',
        'MRestoreController'        => '/controller/revisions/MRestoreController.php',
        'MSearchController'         => '/controller/MSearchController.php',
        'MDownloadEventController'  => '/controller/MDownloadEventController.php',
    
        'MBtUpload'        => '/controller/files/MBtUpload.php',
    
                                'MUser'                     => '/model/MUser.php',
        'MUserMeta'                 => '/model/MUserMeta.php',
        'MTeam'                     => '/model/MTeam.php',
        'MUserDevice'               => '/model/MUserDevice.php',
        'MServerToken'              => '/model/MServerToken.php',
        'MFiles'                    => '/model/MFiles.php',
        'MEvents'                   => '/model/MEvents.php',
        'MFileVersions'             => '/model/MFileVersions.php',
        'MUserMetas'                => '/model/MUserMetas.php',
        'MFileMetas'                => '/model/MFileMetas.php',
        'MSystemUpgrade'            => '/model/MSystemUpgrade.php',
        'MShareFiles'               => '/model/MShareFiles.php',
        'MAccessLogs'               => '/model/MAccessLogs.php',
        'MErrorLogs'                => '/model/MErrorLogs.php',
        'MOptions'                  => '/model/MOptions.php',
    	'MServerRegistry'           => '/model/MServerRegistry.php',
    

        
                                'MSecurity'                  => '/controller/security/MSecurity.php',
        'MSecurityClass'             => '/controller/security/MSecurityClass.php',
    
    
    	    	    	    	'MOauthController'           => '/controller/oauth/MOauthController.php',
        'MOauthServerDecide'          => '/controller/oauth/MOauthServerDecide.php',

                                'MAdapterController'         => '/controller/adapter/MAdapterController.php',
    
       	    	    	    	'MUserFilter'                => '/filter/MUserFilter.php',   
        'MActionFilter'              => '/filter/MActionFilter.php',
                                        'Image'                      => '/extentions/image/Image.php',
        'Image_Driver'               => '/extentions/image/Image_Driver.php',
        'CImageComponent'            => '/extentions/image/CImageComponent.php',
        'Image_GD_Driver'            => '/extentions/image/drivers/Image_GD_Driver.php',
        'Image_ImageMagick_Driver'   => '/extentions/image/drivers/Image_ImageMagick_Driver.php',
        'CArray'                     => '/extentions/image/helpers/CArray.php',
        
                                'OAuthDiscovery'                    => '/third/oauth/OAuthDiscovery.php',
        'OAuthException2'                   => '/third/oauth/OAuthException2.php',
        'OAuthRequest'                      => '/third/oauth/OAuthRequest.php',
        'OAuthRequester'                    => '/third/oauth/OAuthRequester.php',
        'OAuthRequestLogger'                => '/third/oauth/OAuthRequestLogger.php',
        'OAuthRequestSigner'                => '/third/oauth/OAuthRequestSigner.php',
        'OAuthRequestVerifier'              => '/third/oauth/OAuthRequestVerifier.php',
        'OAuthServer'                       => '/third/oauth/OAuthServer.php',
        'OAuthSession'                      => '/third/oauth/OAuthSession.php',
        'OAuthStore'                        => '/third/oauth/OAuthStore.php',
        'OAuthBodyContentDisposition'       => '/third/oauth/body/OAuthBodyContentDisposition.php',
        'OAuthBodyMultipartFormdata'        => '/third/oauth/body/OAuthBodyMultipartFormdata.php',
        'OAuthSessionAbstract'              => '/third/oauth/session/OAuthSessionAbstract.class.php',
        'OAuthSessionSESSION'               => '/third/oauth/session/OAuthSessionSESSION.php',
        'OAuthSignatureMethod'              => '/third/oauth/signature_method/OAuthSignatureMethod.class.php',
        'OAuthSignatureMethod_HMAC_SHA1'    => '/third/oauth/signature_method/OAuthSignatureMethod_HMAC_SHA1.php',
        'OAuthSignatureMethod_MD5'          => '/third/oauth/signature_method/OAuthSignatureMethod_MD5.php',
        'OAuthSignatureMethod_PLAINTEXT'    => '/third/oauth/signature_method/OAuthSignatureMethod_PLAINTEXT.php',
        'OAuthSignatureMethod_RSA_SHA1'     => '/third/oauth/signature_method/OAuthSignatureMethod_RSA_SHA1.php',
        'OAuthStoreAbstract'                => '/third/oauth/store/OAuthStoreAbstract.php',
        'OAuthStore2Leg'                    => '/third/oauth/store/OAuthStore2Leg.php',
        'OAuthStoreAnymeta'                 => '/third/oauth/store/OAuthStoreAnymeta.php',
        'OAuthStoreMySQL'                   => '/third/oauth/store/OAuthStoreMySQL.php',
        'OAuthStoreSQL'                     => '/third/oauth/store/OAuthStoreSQL.php'
    );
}


require_once(FXP_PATH.'/common/oauth_init.php');